import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/Login',
    component: () => import('@/LoginView'),
    // 路径为 / 显示的页面
    alias: '/'
  },
  {
    path: '/Home',
    component: () => import('@/HomeView'),
    children: [
      {
        path: '/Sort',
        component: () => import('@/components/SortManage'),
      },
      {
        path: '/Tag',
        component: () => import('@/components/TagList'),
      },
      {
        path: '/Article',
        component: () => import('@/components/ArticleList'),
      },
      {
        path: '/Link',
        component: () => import('@/components/LinkList'),
      },
      {
        path: '/User',
        component: () => import('@/components/UserList'),
      },
      {
        path: '/Test',
        component: () => import('@/components/TestOne'),
      }
    ]
  },
  {
    path: '/*',
    component: () => import('@/components/NotFound'),
  }
]

const router = new VueRouter({
  routes,
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
